from dataclasses import dataclass
import os, sys, re, codecs, binascii, datetime, pickle

from lodger import Lodger
from lodger import LodgerItem
from flask import Flask
from flask import render_template
from flask import g

app = Flask(__name__)

def GetLodger():
    if 'lodger' not in g:
        g.lodger = Lodger()
    return g.lodger

@app.route("/")
def lodgerindex():
    return GetLodger().ShowLodger()

@app.route("/showform/<int:id>")
def showform(id):
    return GetLodger().ShowForm(id)

@app.route("/delete/<int:id>")
def deleteitem(id):
    return GetLodger().Delete(id)

@app.route("/add", methods=['POST'])
def add():
    return GetLodger().Add()

@app.teardown_appcontext
def teardown_lodger(ctx):
    GetLodger().storage.Store()

if __name__ == "__main__":
    app.run(debug=True)